package com.styytech.dadabao.api.requestresult;

import com.styytech.dadabao.api.response.AbstractResponseResult;
import com.styytech.dadabao.bean.ListData;
import com.styytech.dadabao.utils.ParseJsonUtils;

import org.json.JSONArray;

/**
 * Created by User on 2015/8/3.
 */
public class ListDataResult extends RequestResult {
    /**
     * 构造函数
     *
     * @param httpResponseResult
     */
    int httpType;

    public ListDataResult(AbstractResponseResult httpResponseResult, int httpType) {
        super(httpResponseResult);
        this.httpType = httpType;
    }

    @Override
    public void doBusiness() {
        super.doBusiness();
        if (super.isSuccess()) {
            dataParse((JSONArray) super.getRows());
        }
    }

    private void dataParse(JSONArray jsonArray) {
        ListData listData = ParseJsonUtils.ParseListData(jsonArray, httpType);
        listData.setPageNum(super.getPage());
        listData.setTotlePageNum(super.getPages());

        if (httpResponseResult != null) {
            httpResponseResult.executeSuccess(listData);
        }
    }
}
